package com.nciae.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController("/upload")
public class UploadController {


    @PostMapping
    public String upload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return "上传失败，请选择文件";
        }

        String fileName = file.getOriginalFilename();
        String filePath = "D:/开发项目/redbag/src/main/resource/template/";
        File dest = new File(filePath + fileName);
        try {
            file.transferTo(dest);
            return dest.getAbsolutePath();
        } catch (IOException e) {
            System.out.println(e);
        }
        return "上传失败！";
    }
}